package mya_dc.shared_classes.externalExecuter;

import java.util.*;
import mya_dc.shared_classes.CompilationErrors;
import mya_dc.shared_classes.MyaCompilationError;

/**
 * Compilation output log device.
 * <br>Logs errors and warnings as outputed by g++.exe 
 * 
 * @author Yuval Shimron
 * 	  <br> MYA
 *
 */
public class ILogDevice
{
	public CompilationErrors m_Errors;
	
	public ILogDevice()
	{
		m_Errors = new CompilationErrors();
	}
	
	/**
	 * log - logs a message.
	 * <br>
	 * <br>If possible, tries to break message to file name and line number.
	 * 
	 * @param strError - error string
	 */
	public void log(String strError)
	{
		StringTokenizer Tok = new StringTokenizer(strError,":");
        String FileName = null;
        String LineNumber = null;
        
        if (Tok.hasMoreElements())
        	FileName = Tok.nextElement().toString() + ":" + Tok.nextElement().toString();
	
	 	if (Tok.hasMoreElements())
	 		LineNumber = Tok.nextElement().toString(); 
	 		try {
	 			Integer.parseInt(LineNumber);
	 			// might not contain a number since sometimes errors don't give a line #.
	 		} catch (Exception e) {
	 			LineNumber = "";
	 		}
	 
	 	// strError contains the whole string... seams more reasonable.
	 	m_Errors.addLast(new MyaCompilationError(FileName, LineNumber, strError));
	}
}
